﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using PetaPoco;

namespace DAL
{
    public static class DbScoure
    {
        private static Database db;
        public static Database DataBase()
        {
            if (db == null)
            {
                ConnectionStringSettings conn;
                switch (ConfigurationManager.AppSettings["DAL"].ToLower())
                {
                    case "mysql":
                        conn = ConfigurationManager.ConnectionStrings["PetaPocoMysqlConn"];
                        db = new Database(conn.ConnectionString, MySqlClientFactory.Instance);
                        break;
                    case "sqlite":
                        conn = ConfigurationManager.ConnectionStrings["PetaPocoSqliteConn"];
                        db = new Database(conn.ConnectionString, SQLiteFactory.Instance);
                        break;
                    case "sqlserver":
                        conn = ConfigurationManager.ConnectionStrings["PetaPocoSqlserverConn"];
                        db = new Database(conn.ConnectionString, SqlClientFactory.Instance);
                        break;
                }
            }
            return db;
        }
    }
}
